const apiurl='https://app.yuxiang123.cn/';

import Vue from 'vue';
import App from './App';

import uView from "uview-ui";
Vue.use(uView);

import member from './commen/common.js'
Vue.prototype.$member = member;
	
// 全局mixins，用于实现setData等功能';
import Mixin from './polyfill/mixins';
Vue.mixin(Mixin);

Vue.config.productionTip = false;

App.mpType = 'app';

const app = new Vue({
  ...App,
});
app.$mount();

//请求
import http from '@/commen/js/http/index.js'
//设置baseUrls
http.config.baseUrl = apiurl+"api/";
Vue.prototype.$url = apiurl+"api/";

http.interceptor.request = (config) => {
	//添加通用参数
	config.header = {
		"token":uni.getStorageSync('token'),
		"content-type": "application/x-www-form-urlencoded"
	}
}
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
	    // 判断返回状态 执行相应操作
		if(response.data.ret == -1){
			if(uni.getStorageSync('num') == 1){
				uni.setStorageSync('num', 0);
				// uni.switchTab({
				// 	url:'/pages/shop/shopClass'
				// })
			}else{
				uni.setStorageSync('num', 0);
				// uni.navigateTo({
				// 	url:'/subone/public/login',
				// 	animationType:'slide-in-bottom',
				// 	animationDuration: 700
				// })
			}
		}
	    return response;
	}
Vue.prototype.$http = http
//跳转封装
const Route = (url,type) => {
	//导航跳转
	if (type == 'tab') {
		uni.switchTab({
			url:url
		})
	} else if (type == 'to') {
		uni.navigateTo({
			url: url
		});
	} else if (type == 'url') {
		uni.navigateTo({
			url: '/pages/webView/webView?url=' + url
		});
	}
}
Vue.prototype.$Route = Route
//交互反馈
const toast = (text,time) =>{
	if(time == undefined){
		time = 2
	}
	time = time * 1000
	uni.showToast({
	    title: text,
	    duration: time,
		icon:'none'
	});
}
Vue.prototype.$Toast = toast
const showLoding = (title) =>{
	uni.showLoading({
		title:title || '加载中'
	})
}
Vue.prototype.$show= showLoding
const hideLoding = () =>{
	uni.hideLoading()
}
Vue.prototype.$hide = hideLoding


